fix: Optimize tab focus navigation in Remote Management#527
Conversation
|
TAG Bot New tag: 6.5.34 |
|
TAG Bot New tag: 6.5.35 |
|
TAG Bot New tag: 6.5.36 |
|
TAG Bot New tag: 6.5.37 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: JWWTSL, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
log: setCurrentIndex(...) is called synchronously within the focusOut slot, which triggers setFocus() on the newly selected ItemWidget. Although Qt's focus transfer doesn't actually complete until after focusOutEvent finishes, calling setFocus() synchronously inside a slot is an established pattern already used by existing lambdas in this codebase (the original code also directly called m_pushButton->setFocus() in the slot), so it should be stable. If focus jittering or recursion occurs during testing, fall back to using QMetaObject::invokeMethod(..., Qt::QueuedConnection) for deferred execution. pms: bug-283743
deepin pr auto review★ 总体评分:85分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // listview.cpp:消除重复代码的优化实现
static bool isFocusableItemType(ItemFuncType t)
{
return t != ItemFuncType_GroupLabel && t != ItemFuncType_ItemLabel;
}
// 提取通用查找逻辑
int ListView::findFocusableIndex(int start, int end, int step)
{
for (int i = start; i != end + step; i += step) {
if (i >= 0 && i < m_itemList.count() && isFocusableItemType(m_itemList.at(i)->getFuncType())) {
return i;
}
}
return -1;
}
int ListView::firstFocusableIndex()
{
return m_itemList.isEmpty() ? -1 : findFocusableIndex(0, m_itemList.count() - 1, 1);
}
int ListView::lastFocusableIndex()
{
return m_itemList.isEmpty() ? -1 : findFocusableIndex(m_itemList.count() - 1, 0, -1);
}
int ListView::nextFocusableIndex(int from)
{
return findFocusableIndex(from + 1, m_itemList.count() - 1, 1);
}
int ListView::prevFocusableIndex(int from)
{
return findFocusableIndex(from - 1, 0, -1);
}// remotemanagementpanel.cpp:修复边界fallback逻辑
void RemoteManagementPanel::setFocusInPanel()
{
if (m_listWidget->isVisible()) {
qCDebug(remotemanage) << "list widget is visible, setting focus";
/******** Modify by ut000610 daizhengwen 2020-07-27:bug#39775 Begin***************/
// 将焦点设置在列表里的第一个可聚焦项
int idx = m_listWidget->firstFocusableIndex();
if (idx >= 0) {
m_listWidget->setCurrentIndex(idx);
} else {
// 列表为空或全为不可聚焦项时,直接将焦点设置到添加按钮
m_pushButton->setFocus();
}
/********************* Modify by ut000610 daizhengwen End ************************/
} else {
qCDebug(remotemanage) << "setting focus on add button";
m_pushButton->setFocus();
}
} |
|
/forcemerge |
log: setCurrentIndex(...) is called synchronously within the focusOut slot, which triggers setFocus() on the newly selected ItemWidget. Although Qt's focus transfer doesn't actually complete until after focusOutEvent finishes, calling setFocus() synchronously inside a slot is an established pattern already used by existing lambdas in this codebase (the original code also directly called m_pushButton->setFocus() in the slot), so it should be stable. If focus jittering or recursion occurs during testing, fall back to using QMetaObject::invokeMethod(..., Qt::QueuedConnection) for deferred execution.
pms: bug-283743